package com.atguigu.lease.common.minio;

import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author zhaolingqiao
 * @CreateTime 2024/12/10
 */
@EnableConfigurationProperties(MinioProperties.class)//将属性类注入ioc容器中
@ConditionalOnProperty(prefix = "minio",value = "endpoint")
@Configuration
public class MinioConfiguration {
    @Autowired
    private MinioProperties minioProperties;

    /*装配 minioclient 到 ioc 容器中*/
    @Bean
    public MinioClient minioClient(){
        MinioClient minioClient = MinioClient.builder()
                .endpoint(minioProperties.getEndpoint())
                .credentials(minioProperties.getAccessKey(), minioProperties.getSecretKey())
                .build();
        return minioClient;
    }
}
